import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';

declare var layui: any;
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';

  user: string;

  constructor(
    private router: Router
  ) { }

  ngOnInit() {


    layui.use(['layer', 'form', 'util'], function () {
      var $ = layui.jquery,
        form = layui.form, //表单
        layer = layui.layer, //弹层
        util = layui.util; //右下角返回顶部

        //登录触发事件
        var active = {
          notice: function() {
              //示范一个公告层
              layer.open({
                  type: 1,
                  title: false, //不显示标题栏
                  closeBtn: 0,
                  area: ['750px;', '500px'],
                  shade: 0.8,
                  id: 'LAY_layuipro' ,//设定一个id，防止重复弹出
                  moveType: 1, //拖拽模式，0或者1
                  content: $("#layerFormSignIn")//具体弹层的html代码在在sign-in.component.html的id为layformSignIn的块里，设为不可见
                      
              })
          }

      };
      $('#signIn').on('click', function () {
        var othis = $(this),
          method = othis.data('method');
        active[method] ? active[method].call(this, othis) : '';
      });


      //注册触发事件
      var active1 = {
        notice: function () {
          //示范一个公告层
          layer.open({
              type: 1,
              title: false, //不显示标题栏
              closeBtn: 0,
              area: ['750px;', '550px'],
              shade: 0.8,
              id: 'LAY_layuipro' ,//设定一个id，防止重复弹出
              moveType: 1, //拖拽模式，0或者1
              content: $("#layerFormSignUp")//具体弹层的html代码在sign-up.component.html的id为layformSignUp的块里，设为不可见
                  
          })
        }

      };
      $('#signUp').on('click', function () {
        var othis = $(this),
          method = othis.data('method');
        active1[method] ? active1[method].call(this, othis) : '';
      });

      //右下角返回顶部固定块
      util.fixbar({
        click: function (type) {
        }
      });



    });

    const divSignIn = document.getElementById('sign-in');
    const divSignUp = document.getElementById('sign-up');
    const divSignOut = document.getElementById('sign-out');

    this.user = localStorage.getItem('userId');

    if (localStorage.getItem('userId') !== null) {
      //已登录
      this.user = localStorage.getItem('userId');
    }
    else {
      this.user='0';
    }
  }

  logout() {
    localStorage.removeItem('userId');
    this.router.navigate(['/index']);
    location.reload();
  }
}
